﻿import { NeDBDataContext, MysqlDataContext, EntityObject, SqliteDataContext } from 'tiny-entity';
import { IEntityObject, IDataContext } from "tiny-entity/tinyDB";
import {
    Employee,
    User,
    Table,
    TableGroup,
    TableParty,
    TableZone,
    TableFeeRule,
    Inventory,
    Unit,
    Modifier,
    Category,
    Order,
    Token,
    Upload,
    Updates,
    Resource,
    KitchenOrder,
    Device,
    Kitchensolution,
    SoldOut,
    SerinalNoSeed,
    Store,
    ExpeditionOrder,
    DeliveryOrder,
    Promotion,
    FrontStoreStock,
    ProduceRecord,
    InventoryProduceInfo,
    StorageReceipt,
    StorageReceiptItem
} from './model';

var webconfig = require("../../webconfig").webconfig;

export interface FBSDataContextBase extends IDataContext {
    Employee: Employee;
    User: User;
    Table: Table;
    TableGroup: TableGroup;
    TableZone: TableZone;
    TableParty: TableParty;
    TableFeeRule: TableFeeRule;
    Inventory: Inventory;
    Category: Category;
    Unit: Unit;
    Modifier: Modifier;
    Order: Order;
    Token: Token;
    Upload: Upload;
    Updates: Updates;
    Resource: Resource;
    KitchenOrder: KitchenOrder;
    Device: Device;
    Kitchensolution: Kitchensolution;
    SoldOut: SoldOut;
    SerinalNoSeed: SerinalNoSeed;
    Store: Store;
    ExpeditionOrder: ExpeditionOrder;
    DeliveryOrder: DeliveryOrder,
    Promotion: Promotion;
    FrontStoreStock: FrontStoreStock;
    ProduceRecord: ProduceRecord;
    InventoryProduceInfo: InventoryProduceInfo;
    StorageReceipt: StorageReceipt;
    StorageReceiptItem: StorageReceiptItem;
}
export class FBSDataContextNeDB extends NeDBDataContext implements FBSDataContextBase {
    private employee: Employee;
    private user: User;
    private table: Table;
    private tableGroup: TableGroup;
    private tableZone: TableZone;
    private tableParty: TableParty;
    private tableFeeRule: TableFeeRule;
    private inventory: Inventory;
    private category: Category;
    private unit: Unit;
    private modifier: Modifier;
    private order: Order;
    private token: Token;
    private upload: Upload;
    private updates: Updates;
    private resource: Resource;
    private kitchenOrder: KitchenOrder;
    private device: Device;
    private kitchensolution: Kitchensolution;
    private soldOut: SoldOut;
    private serinalNoSeed: SerinalNoSeed;
    private store: Store;
    private expeditionOrder: ExpeditionOrder;
    private deliveryOrder: DeliveryOrder;
    private promotion: Promotion;
    private frontStoreStock: FrontStoreStock;
    private produceRecord: ProduceRecord;
    private inventoryProduceInfo: InventoryProduceInfo;
    private storageReceipt: StorageReceipt;
    private storageReceiptItem: StorageReceiptItem;


    constructor() {
        super({ FilePath: webconfig.dataRootDir + "/", DBName: "", IsMulitTabel: true });

        this.employee = new Employee(this);
        this.user = new User(this);
        this.table = new Table(this);
        this.tableGroup = new TableGroup(this);
        this.tableZone = new TableZone(this);
        this.tableParty = new TableParty(this);
        this.tableFeeRule = new TableFeeRule(this);
        this.inventory = new Inventory(this);
        this.category = new Category(this);
        this.unit = new Unit(this);
        this.modifier = new Modifier(this);
        this.order = new Order(this);
        this.token = new Token(null, "", this);
        this.kitchenOrder = new KitchenOrder(this);
        this.device = new Device(this);
        this.kitchensolution = new Kitchensolution(this);
        this.soldOut = new SoldOut(this);
        this.serinalNoSeed = new SerinalNoSeed(this);
        this.store = new Store(this);
        this.expeditionOrder = new ExpeditionOrder(this);
        this.deliveryOrder = new DeliveryOrder(this);
        this.promotion = new Promotion(this);
        this.frontStoreStock = new FrontStoreStock(this);
        this.produceRecord = new ProduceRecord(this);
        this.inventoryProduceInfo = new InventoryProduceInfo(this);
        this.storageReceipt = new StorageReceipt(this);
        this.storageReceiptItem = new StorageReceiptItem(this);
    }

    get Employee() { return this.employee; }
    get User() { return this.user; }
    get Table() { return this.table; }
    get TableGroup() { return this.tableGroup; }
    get TableZone() { return this.tableZone; }
    get TableParty() { return this.tableParty; }
    get TableFeeRule() { return this.tableFeeRule; }
    get Inventory() { return this.inventory; }
    get Category() { return this.category; }
    get Unit() { return this.unit; }
    get Modifier() { return this.modifier; }
    get Order() { return this.order; }
    get Token() { return this.token; }
    get Upload() { return this.upload; }
    get Updates() { return this.updates; }
    get Resource() { return this.resource; }
    get KitchenOrder() { return this.kitchenOrder; }
    get Device() { return this.device; }
    get Kitchensolution() { return this.kitchensolution; }
    get SoldOut() { return this.soldOut; }
    get SerinalNoSeed() { return this.serinalNoSeed; }
    get Store() { return this.store; }
    get ExpeditionOrder() { return this.expeditionOrder; }
    get DeliveryOrder() { return this.deliveryOrder; }
    get Promotion() { return this.promotion; }
    get FrontStoreStock() { return this.frontStoreStock };
    get ProduceRecord() { return this.produceRecord };
    get InventoryProduceInfo() { return this.inventoryProduceInfo };
    get StorageReceipt() { return this.storageReceipt };
    get StorageReceiptItem() { return this.storageReceiptItem };


    GetEntityObject(typeName: string): IEntityObject {
        switch (typeName.toLowerCase()) {
            case this.employee.toString().toLowerCase(): return new Employee();
            case this.table.toString().toLowerCase(): return new Table();
            case this.tableGroup.toString().toLowerCase(): return new TableGroup();
            case this.tableZone.toString().toLowerCase(): return new TableZone();
            case this.tableParty.toString().toLowerCase(): return new TableParty();
            case this.tableFeeRule.toString().toLowerCase(): return new TableFeeRule();
            case this.inventory.toString().toLowerCase(): return new Inventory();
            case this.category.toString().toLowerCase(): return new Category();
            case this.unit.toString().toLowerCase(): return new Unit();
            case this.modifier.toString().toLowerCase(): return new Modifier();
            case this.order.toString().toLowerCase(): return new Order();
            case this.kitchenOrder.toString().toLowerCase(): return new KitchenOrder();
            case this.device.toString().toLowerCase(): return new Device();
            case this.kitchensolution.toString().toLowerCase(): return new Kitchensolution();
            case this.soldOut.toString().toLowerCase(): return new SoldOut();
            case "preorders": return new Order();
            case this.store.toString().toLowerCase(): return new Store();
            case this.expeditionOrder.toString().toLowerCase(): return new ExpeditionOrder();
            case this.deliveryOrder.toString().toLowerCase(): return new DeliveryOrder();
            // case this.promotion.toString().toLowerCase(): return new Promotion();
            case this.frontStoreStock.toString().toLowerCase(): return new FrontStoreStock();
            case this.produceRecord.toString().toLowerCase(): return new ProduceRecord();
            case this.inventoryProduceInfo.toString().toLowerCase(): return new InventoryProduceInfo();
            case this.storageReceipt.toString().toLowerCase(): return new StorageReceipt();
            case this.storageReceiptItem.toString().toLowerCase(): return new StorageReceiptItem();
            default: return null;
        }
    }

    GetCtxEntity(typeName: string): any {
        switch (typeName.toLowerCase()) {
            case "preorders": return this.Order;
            case this.employee.toString().toLowerCase(): return this.Employee;
            case this.table.toString().toLowerCase(): return this.Table;
            case this.tableGroup.toString().toLowerCase(): return this.TableGroup;
            case this.tableZone.toString().toLowerCase(): return this.TableZone;
            case this.tableParty.toString().toLowerCase(): return this.TableParty;
            case this.tableFeeRule.toString().toLowerCase(): return this.TableFeeRule;
            case this.inventory.toString().toLowerCase(): return this.Inventory;
            case this.category.toString().toLowerCase(): return this.Category;
            case this.unit.toString().toLowerCase(): return this.Unit;
            case this.modifier.toString().toLowerCase(): return this.Modifier;
            case this.order.toString().toLowerCase(): return this.Order;
            case this.kitchenOrder.toString().toLowerCase(): return this.kitchenOrder;
            case this.device.toString().toLowerCase(): return this.device;
            case this.kitchensolution.toString().toLowerCase(): return this.kitchensolution;
            case this.soldOut.toString().toLowerCase(): return this.SoldOut;
            case this.store.toString().toLowerCase(): return this.store;
            case this.expeditionOrder.toString().toLowerCase(): return this.expeditionOrder;
            case this.deliveryOrder.toString().toLowerCase(): return this.deliveryOrder;
            // case this.promotion.toString().toLowerCase(): return this.promotion;
            case this.frontStoreStock.toString().toLowerCase(): return this.frontStoreStock;
            case this.produceRecord.toString().toLowerCase(): return this.produceRecord;
            case this.inventoryProduceInfo.toString().toLowerCase(): return this.inventoryProduceInfo;
            case this.storageReceipt.toString().toLowerCase(): return this.storageReceipt;
            case this.storageReceiptItem.toString().toLowerCase(): return this.storageReceiptItem;
            default: return null;
        }
    }
}
export class FBSDataContextMysql extends MysqlDataContext implements FBSDataContextBase {
    private employee: Employee;
    private user: User;
    private table: Table;
    private tableGroup: TableGroup;
    private tableZone: TableZone;
    private tableParty: TableParty;
    private tableFeeRule: TableFeeRule;
    private inventory: Inventory;
    private category: Category;
    private unit: Unit;
    private modifier: Modifier;
    private order: Order;
    private token: Token;
    private upload: Upload;
    private updates: Updates;
    private resource: Resource;
    private kitchenOrder: KitchenOrder;
    private device: Device;
    private kitchensolution: Kitchensolution;
    private soldOut: SoldOut;
    private serinalNoSeed: SerinalNoSeed;
    private store: Store;
    private expeditionOrder: ExpeditionOrder;
    private deliveryOrder: DeliveryOrder;
    private promotion: Promotion;
    private frontStoreStock: FrontStoreStock;
    private produceRecord: ProduceRecord;
    private inventoryProduceInfo: InventoryProduceInfo;
    private storageReceipt: StorageReceipt;
    private storageReceiptItem: StorageReceiptItem;

    constructor() {
        super(webconfig.mysqlConnOption);

        this.employee = new Employee(this);
        this.user = new User(this);
        this.table = new Table(this);
        this.tableGroup = new TableGroup(this);
        this.tableZone = new TableZone(this);
        this.tableParty = new TableParty(this);
        this.tableFeeRule = new TableFeeRule(this);
        this.inventory = new Inventory(this);
        this.category = new Category(this);
        this.unit = new Unit(this);
        this.modifier = new Modifier(this);
        this.order = new Order(this);
        this.token = new Token(null, "", this);
        this.kitchenOrder = new KitchenOrder(this);
        this.device = new Device(this);
        this.kitchensolution = new Kitchensolution(this);
        this.soldOut = new SoldOut(this);
        this.serinalNoSeed = new SerinalNoSeed(this);
        this.store = new Store(this);
        this.expeditionOrder = new ExpeditionOrder(this);
        this.deliveryOrder = new DeliveryOrder(this);
        this.promotion = new Promotion(this);
        this.frontStoreStock = new FrontStoreStock(this);
        this.produceRecord = new ProduceRecord(this);
        this.inventoryProduceInfo = new InventoryProduceInfo(this);
        this.storageReceipt = new StorageReceipt(this);
        this.storageReceiptItem = new StorageReceiptItem(this);
    }

    get Employee() { return this.employee; }
    get User() { return this.user; }
    get Table() { return this.table; }
    get TableGroup() { return this.tableGroup; }
    get TableZone() { return this.tableZone; }
    get TableParty() { return this.tableParty; }
    get TableFeeRule() { return this.tableFeeRule; }
    get Inventory() { return this.inventory; }
    get Category() { return this.category; }
    get Unit() { return this.unit; }
    get Modifier() { return this.modifier; }
    get Order() { return this.order; }
    get Token() { return this.token; }
    get Upload() { return this.upload; }
    get Updates() { return this.updates; }
    get Resource() { return this.resource; }
    get KitchenOrder() { return this.kitchenOrder; }
    get Device() { return this.device; }
    get Kitchensolution() { return this.kitchensolution; }
    get SoldOut() { return this.soldOut; }
    get SerinalNoSeed() { return this.serinalNoSeed; }
    get Store() { return this.store; }
    get ExpeditionOrder() { return this.expeditionOrder; }
    get DeliveryOrder() { return this.deliveryOrder; }
    get Promotion() { return this.promotion; }
    get FrontStoreStock() { return this.frontStoreStock };
    get ProduceRecord() { return this.produceRecord };
    get InventoryProduceInfo() { return this.inventoryProduceInfo };
    get StorageReceipt() { return this.storageReceipt };
    get StorageReceiptItem() { return this.storageReceiptItem };


    GetEntityObject(typeName: string): IEntityObject {
        switch (typeName.toLowerCase()) {
            case this.employee.toString().toLowerCase(): return new Employee();
            case this.table.toString().toLowerCase(): return new Table();
            case this.tableGroup.toString().toLowerCase(): return new TableGroup();
            case this.tableZone.toString().toLowerCase(): return new TableZone();
            case this.tableParty.toString().toLowerCase(): return new TableParty();
            case this.tableFeeRule.toString().toLowerCase(): return new TableFeeRule();
            case this.inventory.toString().toLowerCase(): return new Inventory();
            case this.category.toString().toLowerCase(): return new Category();
            case this.unit.toString().toLowerCase(): return new Unit();
            case this.modifier.toString().toLowerCase(): return new Modifier();
            case this.order.toString().toLowerCase(): return new Order();
            case this.kitchenOrder.toString().toLowerCase(): return new KitchenOrder();
            case this.device.toString().toLowerCase(): return new Device();
            case this.kitchensolution.toString().toLowerCase(): return new Kitchensolution();
            case this.soldOut.toString().toLowerCase(): return new SoldOut();
            case "preorders": return new Order();
            case this.store.toString().toLowerCase(): return new Store();
            case this.expeditionOrder.toString().toLowerCase(): return new ExpeditionOrder();
            case this.deliveryOrder.toString().toLowerCase(): return new DeliveryOrder();
            // case this.promotion.toString().toLowerCase(): return new Promotion();
            case this.frontStoreStock.toString().toLowerCase(): return new FrontStoreStock();
            case this.produceRecord.toString().toLowerCase(): return new ProduceRecord();
            case this.inventoryProduceInfo.toString().toLowerCase(): return new InventoryProduceInfo();
            case this.storageReceipt.toString().toLowerCase(): return new StorageReceipt();
            case this.storageReceiptItem.toString().toLowerCase(): return new StorageReceiptItem();
            default: return null;
        }
    }

    GetCtxEntity(typeName: string): any {
        switch (typeName.toLowerCase()) {
            case "preorders": return this.Order;
            case this.employee.toString().toLowerCase(): return this.Employee;
            case this.table.toString().toLowerCase(): return this.Table;
            case this.tableGroup.toString().toLowerCase(): return this.TableGroup;
            case this.tableZone.toString().toLowerCase(): return this.TableZone;
            case this.tableParty.toString().toLowerCase(): return this.TableParty;
            case this.tableFeeRule.toString().toLowerCase(): return this.TableFeeRule;
            case this.inventory.toString().toLowerCase(): return this.Inventory;
            case this.category.toString().toLowerCase(): return this.Category;
            case this.unit.toString().toLowerCase(): return this.Unit;
            case this.modifier.toString().toLowerCase(): return this.Modifier;
            case this.order.toString().toLowerCase(): return this.Order;
            case this.kitchenOrder.toString().toLowerCase(): return this.kitchenOrder;
            case this.device.toString().toLowerCase(): return this.device;
            case this.kitchensolution.toString().toLowerCase(): return this.kitchensolution;
            case this.soldOut.toString().toLowerCase(): return this.SoldOut;
            case this.store.toString().toLowerCase(): return this.store;
            case this.expeditionOrder.toString().toLowerCase(): return this.expeditionOrder;
            case this.deliveryOrder.toString().toLowerCase(): return this.deliveryOrder;
            case this.frontStoreStock.toString().toLowerCase(): return this.frontStoreStock;
            case this.produceRecord.toString().toLowerCase(): return this.produceRecord;
            case this.inventoryProduceInfo.toString().toLowerCase(): return this.inventoryProduceInfo;
            case this.storageReceipt.toString().toLowerCase(): return this.storageReceipt;
            case this.storageReceiptItem.toString().toLowerCase(): return this.storageReceiptItem;
            default: return null;
        }
    }
}

export class FBSDataContextSqlite extends SqliteDataContext implements FBSDataContextBase {
    private employee: Employee;
    private user: User;
    private table: Table;
    private tableGroup: TableGroup;
    private tableZone: TableZone;
    private tableParty: TableParty;
    private tableFeeRule: TableFeeRule;
    private inventory: Inventory;
    private category: Category;
    private unit: Unit;
    private modifier: Modifier;
    private order: Order;
    private token: Token;
    private upload: Upload;
    private updates: Updates;
    private resource: Resource;
    private kitchenOrder: KitchenOrder;
    private device: Device;
    private kitchensolution: Kitchensolution;
    private soldOut: SoldOut;
    private serinalNoSeed: SerinalNoSeed;
    private store: Store;
    private expeditionOrder: ExpeditionOrder;
    private deliveryOrder: DeliveryOrder;
    private promotion: Promotion;
    private frontStoreStock: FrontStoreStock;
    private produceRecord: ProduceRecord;
    private inventoryProduceInfo: InventoryProduceInfo;
    private storageReceipt: StorageReceipt;
    private storageReceiptItem: StorageReceiptItem;

    constructor() {
        super(webconfig.dataRootDir + "\\fbsDB.db");

        this.employee = new Employee(this);
        this.user = new User(this);
        this.table = new Table(this);
        this.tableGroup = new TableGroup(this);
        this.tableZone = new TableZone(this);
        this.tableParty = new TableParty(this);
        this.tableFeeRule = new TableFeeRule(this);
        this.inventory = new Inventory(this);
        this.category = new Category(this);
        this.unit = new Unit(this);
        this.modifier = new Modifier(this);
        this.order = new Order(this);
        this.token = new Token(null, "", this);
        this.kitchenOrder = new KitchenOrder(this);
        this.device = new Device(this);
        this.kitchensolution = new Kitchensolution(this);
        this.soldOut = new SoldOut(this);
        this.serinalNoSeed = new SerinalNoSeed(this);
        this.store = new Store(this);
        this.expeditionOrder = new ExpeditionOrder(this);
        this.deliveryOrder = new DeliveryOrder(this);
        this.promotion = new Promotion(this);
        this.frontStoreStock = new FrontStoreStock(this);
        this.produceRecord = new ProduceRecord(this);
        this.inventoryProduceInfo = new InventoryProduceInfo(this);
        this.storageReceipt = new StorageReceipt(this);
        this.storageReceiptItem = new StorageReceiptItem(this);
    }

    get Employee() { return this.employee; }
    get User() { return this.user; }
    get Table() { return this.table; }
    get TableGroup() { return this.tableGroup; }
    get TableZone() { return this.tableZone; }
    get TableParty() { return this.tableParty; }
    get TableFeeRule() { return this.tableFeeRule; }
    get Inventory() { return this.inventory; }
    get Category() { return this.category; }
    get Unit() { return this.unit; }
    get Modifier() { return this.modifier; }
    get Order() { return this.order; }
    get Token() { return this.token; }
    get Upload() { return this.upload; }
    get Updates() { return this.updates; }
    get Resource() { return this.resource; }
    get KitchenOrder() { return this.kitchenOrder; }
    get Device() { return this.device; }
    get Kitchensolution() { return this.kitchensolution; }
    get SoldOut() { return this.soldOut; }
    get SerinalNoSeed() { return this.serinalNoSeed; }
    get Store() { return this.store; }
    get Promotion() { return this.promotion; }
    get ExpeditionOrder() { return this.expeditionOrder; }
    get DeliveryOrder() { return this.deliveryOrder; }
    get FrontStoreStock() { return this.frontStoreStock };
    get ProduceRecord() { return this.produceRecord };
    get InventoryProduceInfo() { return this.inventoryProduceInfo };
    get StorageReceipt() { return this.storageReceipt };
    get StorageReceiptItem() { return this.storageReceiptItem };

    GetEntityObject(typeName: string): IEntityObject {
        switch (typeName.toLowerCase()) {
            case this.employee.toString().toLowerCase(): return new Employee();
            case this.table.toString().toLowerCase(): return new Table();
            case this.tableGroup.toString().toLowerCase(): return new TableGroup();
            case this.tableZone.toString().toLowerCase(): return new TableZone();
            case this.tableParty.toString().toLowerCase(): return new TableParty();
            case this.tableFeeRule.toString().toLowerCase(): return new TableFeeRule();
            case this.inventory.toString().toLowerCase(): return new Inventory();
            case this.category.toString().toLowerCase(): return new Category();
            case this.unit.toString().toLowerCase(): return new Unit();
            case this.modifier.toString().toLowerCase(): return new Modifier();
            case this.order.toString().toLowerCase(): return new Order();
            case this.kitchenOrder.toString().toLowerCase(): return new KitchenOrder();
            case this.device.toString().toLowerCase(): return new Device();
            case this.kitchensolution.toString().toLowerCase(): return new Kitchensolution();
            case this.soldOut.toString().toLowerCase(): return new SoldOut();
            case "preorders": return new Order();
            case this.store.toString().toLowerCase(): return new Store();
            case this.expeditionOrder.toString().toLowerCase(): return new ExpeditionOrder();
            case this.deliveryOrder.toString().toLowerCase(): return new DeliveryOrder();
            // case this.promotion.toString().toLowerCase(): return new Promotion();
            case this.frontStoreStock.toString().toLowerCase(): return new FrontStoreStock();
            case this.produceRecord.toString().toLowerCase(): return new ProduceRecord();
            case this.inventoryProduceInfo.toString().toLowerCase(): return new InventoryProduceInfo();
            case this.storageReceipt.toString().toLowerCase(): return new StorageReceipt();
            case this.storageReceiptItem.toString().toLowerCase(): return new StorageReceiptItem();
            default: return null;
        }
    }

    GetCtxEntity(typeName: string): any {
        switch (typeName.toLowerCase()) {
            case "preorders": return this.Order;
            case this.employee.toString().toLowerCase(): return this.Employee;
            case this.table.toString().toLowerCase(): return this.Table;
            case this.tableGroup.toString().toLowerCase(): return this.TableGroup;
            case this.tableZone.toString().toLowerCase(): return this.TableZone;
            case this.tableParty.toString().toLowerCase(): return this.TableParty;
            case this.tableFeeRule.toString().toLowerCase(): return this.TableFeeRule;
            case this.inventory.toString().toLowerCase(): return this.Inventory;
            case this.category.toString().toLowerCase(): return this.Category;
            case this.unit.toString().toLowerCase(): return this.Unit;
            case this.modifier.toString().toLowerCase(): return this.Modifier;
            case this.order.toString().toLowerCase(): return this.Order;
            case this.kitchenOrder.toString().toLowerCase(): return this.kitchenOrder;
            case this.device.toString().toLowerCase(): return this.device;
            case this.kitchensolution.toString().toLowerCase(): return this.kitchensolution;
            case this.soldOut.toString().toLowerCase(): return this.SoldOut;
            case this.store.toString().toLowerCase(): return this.store;
            case this.expeditionOrder.toString().toLowerCase(): return this.expeditionOrder;
            case this.deliveryOrder.toString().toLowerCase(): return this.deliveryOrder;
            case this.frontStoreStock.toString().toLowerCase(): return this.frontStoreStock;
            case this.produceRecord.toString().toLowerCase(): return this.produceRecord;
            case this.inventoryProduceInfo.toString().toLowerCase(): return this.inventoryProduceInfo;
            case this.storageReceipt.toString().toLowerCase(): return this.storageReceipt;
            case this.storageReceiptItem.toString().toLowerCase(): return this.storageReceiptItem;
            default: return null;
        }
    }
}
export class DataContextFactory {
    static GetDataContext(): FBSDataContextBase {
        if (webconfig.dbType == "nedb") return new FBSDataContextNeDB();
        else if (webconfig.dbType == "mysql") return new FBSDataContextMysql();
        else if (webconfig.dbType == "sqlite") return new FBSDataContextSqlite();
    }
}